package com.itany.book.service.impl;

import com.itany.exception.ManagerUserException;
import com.itany.mapper.ManagerUserMapper;
import com.itany.pojo.ManagerUser;
import com.itany.service.ManagerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Author：sl
 * Date：2019-09-17 下午7:00
 * Description：<描述>
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
public class ManagerUserServiceImpl implements ManagerUserService {

    @Autowired
    private ManagerUserMapper mapper;

    //此处的事务注解，会合并类上的注解
    //事务的只读优化
    @Transactional(readOnly = true)
    public ManagerUser login(ManagerUser managerUser) throws ManagerUserException {

        ManagerUser s = mapper.selectByLoginNameAndPassword(managerUser);
        if(null == s){
            throw new ManagerUserException("用户名或密码错误");
        }
        return s;

    }
}
